﻿<%@ Page MasterPageFile="~/Site.Master" Title="Xtablish CRM / Edit User" Language="C#" AutoEventWireup="true"
    CodeBehind="EditUser.aspx.cs" Inherits="Web.Account.EditUser" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="Con1" runat="Server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function getErrorMessage(sender, args) {
                var fileExtention = args.get_fileName().substring(args.get_fileName().lastIndexOf('.') + 1, args.get_fileName().length);
                if (args.get_fileName().lastIndexOf('.') != -1) {//this checks if the extension is correct
                    if (sender.get_allowedFileExtensions().indexOf(fileExtention) == -1) {
                        return ("This file type is not supported.");
                    }
                    else if (args.get_fileInputField().files[0].size > sender._maxFileSize) {
                        return ("This file exceeds the maximum allowed size of 1 MB.");
                    }
                }
                else {
                    return ("not correct extension.");
                }
                return null;
            }
            function AsyncUpload1_OnClientFileSelected(sender, args) {
                var error = getErrorMessage(sender, args);
                if (error == null) {
                    var fileInput = sender;
                    var file = args.get_fileInputField().files[0];
                    var reader = new FileReader();
                    reader.onload = function (e) {
                        $('#imgprw').attr('src', e.target.result);
                    }
                    reader.readAsDataURL(file);
                }
                else
                    ShowMessage(error);
            }
            $.verify.addRules({
                secondaryEmailValidate: function (w) {
                    var regexp = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
                    var url = w.val();
                    var urlvalidate = document.getElementById('<%= txtSecondaryEmailValidate.ClientID %>');
                    if (!regexp.test(url)) {
                        urlvalidate.value = null;
                        return "Invalid email address.";
                    }
                    urlvalidate.value = "email";
                    return true;
                }
            });

            $.verify.addRules({
                primaryEmailValidate: function (w) {
                    var regexp = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
                    var url = w.val();
                   
                    var urlvalidate = document.getElementById('<%= txtPrimaryEmailValidate.ClientID %>');
                    if (!regexp.test(url)) {
                        urlvalidate.value = null;
                        return "Invalid email address.";
                    }
                    urlvalidate.value = "email";
                    return true;
                }
            });
            function WebForm_OnSubmit() {
                if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) {
                    $("#validation_dialog").dialog({
                        title: "Validation Error!",
                        modal: true,
                        resizable: false,
                        buttons: {
                            Close: function () {
                                $(this).dialog('close');
                            }
                        }
                    });
                    return false;
                }
                return true;
            }
            function CancelClick() {
                window.location.assign(document.getElementById('<%= hdntxtPrevPage.ClientID %>').value);
            }
            function disableKeyPress(evt) {
                return false;
            }
            function isNumberKey(evt) {
                var charCode = (evt.which) ? evt.which : evt.keyCode
                if (charCode != 46)
                    if (charCode > 31 && (charCode < 48 || charCode > 57))
                        return false;
                return true;
            }
            
            function showdivPassWord(obj) {
                var chb = document.getElementById("myCheck");
                var el = document.getElementById(obj);
                if (chb.checked == true)
                    el.style.display = 'block';
                else
                    el.style.display = 'none';
            }            
            function OnBlur(sender, args) {
                if (sender.get_value() == "") {
                    sender.set_value("0");
                }
            }
            function OnClientClose(oWnd, args) { }
        </script>
    </telerik:RadCodeBlock>
    <asp:HiddenField ID="hdntxtPrevPage" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtImageEntension" runat="server"></asp:HiddenField>
    <div class="register" id="divContent" runat="server" style="display: block">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-6">
                    <h3>Edit User</h3>
                </div>
                <div class="col-md-6 btn-edit">
                    <asp:LinkButton id="btnTop_Delete" runat="server" class="btn btn-defaul" OnClick="btn_Delete_ServerClick"
                        OnClientClick="return radConfirmDelete(this, 'Are you sure you want to delete this user ?');">
                        <img src="../Images/delete.png" style="width: 18px; height: 18px" />
                        Delete
                    </asp:LinkButton>
                    <asp:LinkButton id="btnTop_Save" type="button" runat="server" class="btn btn-defaul" OnClick="btn_Save_Click">
                        <img src="../Images/save.png" style="width: 18px; height: 18px" />
                        Save
                    </asp:LinkButton>
                    <div id="validation_dialog" style="display: none">
                        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
                    </div>
                    <asp:LinkButton id="btnTop_Cancel" type="button" runat="server" class="btn btn-defaul" OnClientClick="CancelClick()" CausesValidation="false">
                        <img src="../Images/back.png" style="width: 18px; height: 18px" />
                        Back
                    </asp:LinkButton>

                </div>
            </div>
            <div class="row">
                <div class="edit-form highlight">
                    <div class="control-group">
                        <h4>User Login & Role</h4>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">User Name <span class="red-star">*</span></label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtUsername" runat="server" class="form-control" data-validate="required" />
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Display="None" ControlToValidate="txtUsername"
                                        runat="server" ErrorMessage="User Name is required."></asp:RequiredFieldValidator>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Primary Email <span class="red-star">*</span></label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtPrimaryMail" runat="server" class="form-control" data-validate="primaryEmailValidate" />
                                    <div style="display: none">
                                        <asp:TextBox ID="txtPrimaryEmailValidate" runat="server" class="form-control" Text="email" />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator6" Display="None" ControlToValidate="txtPrimaryEmailValidate"
                                            runat="server" ErrorMessage="Invalid Primary Email Address."></asp:RequiredFieldValidator>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">First Name </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtFirstName" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Last Name <span class="red-star">*</span></label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtLastName" runat="server" class="form-control" data-validate="required" />
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" Display="None" ControlToValidate="txtLastName"
                                        runat="server" ErrorMessage="Last Name is required."></asp:RequiredFieldValidator>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Is Active</label>
                            </div>
                            <div class="col-md-8 checkbox-control">
                                <div class="controls">
                                    <asp:CheckBox ID="chbIsActive" runat="server" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Role </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <telerik:RadComboBox ID="ddlRole" runat="server" DataTextField="ROLE_NAME" DataValueField="ID"
                                        Width="60%" Filter="StartsWith" MaxHeight="700px" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div id="divIsAdmin" runat="server" class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Is Admin</label>
                            </div>
                            <div class="col-md-8 checkbox-control">
                                <div class="controls">
                                    <asp:CheckBox ID="chbIsAdmin" runat="server" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>

                </div>
            </div>
            <!-- end row 1 -->
            <div class="row">
                <div class="edit-form highlight">
                    <div class="control-group">
                        <h4>More Information</h4>
                    </div>

                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Designation</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox class="form-control" ID="txtTitle" runat="server" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Fax</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtFax" runat="server" class="form-control" />
                                </div>
                            </div>

                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Department</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtDepartment" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Other Email</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOtherEmail" runat="server" class="form-control" data-validate="secondaryEmailValidate" />
                                    <div style="display: none">
                                        <asp:TextBox ID="txtSecondaryEmailValidate" runat="server" class="form-control" Text="email" />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator7" Display="None" ControlToValidate="txtSecondaryEmailValidate"
                                            runat="server" ErrorMessage="Invalid Secondary Email Address."></asp:RequiredFieldValidator>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Office Phone</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficePhone" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">CRM Phone Extension</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtCRMPhoneEx" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Mobile Phone</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtMobilePhone" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Secondary Phone</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtSecondaryPhone" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Home Phone</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomePhone" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>

                        <div class="clearfix"></div>
                    </div>

                </div>
            </div>
            <!-- end row 3-->
            <div class="row">
                <div class="edit-form highlight">
                    <div class="control-group">
                        <h4>User address</h4>
                    </div>
                    <!--<div class="control-group">
                        <div class="col-md-6">
                        </div>
                        <div class="clearfix"></div>
                    </div>-->
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Street Address</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtStreetAddress" runat="server" TextMode="MultiLine" class="form-control" Rows="1"></asp:TextBox>
                                </div>
                            </div>
                        </div>

                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control country-control">
                            <div class="col-md-4">
                                <label class="control-label">Country</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtCountry" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">City</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtCity" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>

                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">State</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtState" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Postal Code</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtPostalCode" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="edit-form highlight">
                    <div class="control-group">
                        <h4>User Picture</h4>
                    </div>
                    <div class="control-group">
                        <div class="col-md-12 distance-control" style="padding-left:0">
                            <div class="col-md-2" style="padding-top: 12px; padding-bottom: 0;padding-left:0">
                                <label class="control-label">Upload Picture </label>
                            </div>
                            <div class="col-md-10" style="background: #fff none repeat scroll 0 0; padding-top: 6px; padding-bottom: 6px">
                                <div class="controls">
                                    <div class="row" style="padding-left: 10px">
                                        <table style="width: 100px">
                                            <tr>
                                                <td style="width: 80px; border-right:none !important">
                                                    <img runat="server" id="imgprw" style="width: 80px; height: 80px;padding-left: 5px" clientidmode="static"/>
                                                </td>
                                                <td style="width: 20px; vertical-align: top">
                                                    <asp:LinkButton runat="server" OnClick="DeleteImage_Click" ID="lbtnDeleteImage" CausesValidation="false"
                                                        OnClientClick="return radConfirmDelete(this,'Are you sure want to delete this User picture?');">
                                                        <image src="../Images/delete.png" style="width:18px;height:18px"/>
                                                    </asp:LinkButton>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                    <div class="row" style="padding-top: 6px; padding-left: 10px;height:28px">
                                        <telerik:RadAsyncUpload runat="server" ID="AsyncUpload1"
                                            HideFileInput="true"
                                            MultipleFileSelection="Disabled"
                                            AllowedFileExtensions=".jpeg,.jpg,.png,.gif"
                                            MaxFileSize="1000000"
                                            MaxFileInputsCount="1"
                                            OnClientFileSelected="AsyncUpload1_OnClientFileSelected" />
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>

            <!-- end row 4 -->
            <div class="row">
                <div class="col-md-12 btn-edit">
                    <asp:LinkButton id="btnBottom_Delete" runat="server" class="btn btn-defaul" OnClick="btn_Delete_ServerClick"
                        OnClientClick="return radConfirmDelete(this, 'Are you sure you want to delete this user ?');">
                        <img src="../Images/delete.png" style="width: 18px; height: 18px" />
                        Delete
                    </asp:LinkButton>
                    <asp:LinkButton id="btnBottom_Save" class="btn btn-defaul" runat="server" OnClick="btn_Save_Click">
                        <img src="../Images/save.png" style="width: 18px; height: 18px" />
                        Save
                    </asp:LinkButton>
                    <asp:LinkButton id="btnBottom_Cancel" runat="server" class="btn btn-defaul" OnClientClick="CancelClick()" CausesValidation="false">
                        <img src="../Images/back.png" style="width: 18px; height: 18px" />
                        Back
                    </asp:LinkButton>
                </div>
            </div>
        </div>
    </div>
    <div class="register" id="divError" runat="server" style="display: none">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    This user is not exist, click <a href="Users.aspx"><strong>here</strong></a> to go back User list.
                </div>
            </div>
        </div>
    </div>
</asp:Content>
